<?php
/**
 * Created by PhpStorm.
 * User: 技术员专用
 * Date: 2019/3/19
 * Time: 10:57
 */

namespace app\index\controller;


use app\common\lib\Redis;
use app\common\lib\redis\Predis;
use app\common\lib\Util;

class Login
{
    public function index()
    {
        $phone=intval(request()->param('phone_num'));
        $code=intval(request()->param('code'));
        if (empty($phone) || empty($code)){
            return Util::show(0,'phone or code is null');
        }
        $redisCode=Predis::getInstance()->get(Redis::smsKey($phone));
       if ($code==$redisCode){
           $data=[
               'user'=>$phone,
               'srcKey'=>md5(Redis::userKey($phone)),
               'time'=>time(),
               'isLogin'=>true,
           ];
           Predis::getInstance()->set(Redis::userKey($phone),$data);
           return Util::show(1,'ok',$data);
       }else{
           return Util::show(0,'login error');
       }
    }

}